const Router = require("koa-router");
const { koaBody } = require("koa-body");
const useFileRoute = require("./file");
const useUserRoute = require("./user");
const useWordRoute = require("./word");

module.exports = (app) => {
  const router = new Router();
  const apiRouter = new Router();
  router.get("/", (ctx, next) => {
    console.log(ctx, "ctx--------------我被请求了");
    ctx.type = "text/html";
    ctx.body = "<html>这是koa啊</html>";
  });

  useFileRoute(apiRouter);
  useUserRoute(apiRouter);
  useWordRoute(apiRouter);

  //设定api路由为router的子路由
  router.use("/api", apiRouter.routes(), apiRouter.allowedMethods());

  // 使用中间件
  app.use(koaBody({ multipart: true }));

  app.use(router.routes());
  app.use(router.allowedMethods());
};
